package com.lottery.im.module.chat.adapter;

import android.support.annotation.Nullable;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lottery.im.R;
import com.lottery.im.api.result.entity.GroupNotice;
import com.lottery.im.constant.Constants;
import java.util.List;

/**
 * 群公告
 */
public class GroupNoticeAdapter extends BaseQuickAdapter<GroupNotice, BaseViewHolder> {

  public GroupNoticeAdapter(@Nullable List<GroupNotice> data) {
    super(R.layout.item_group_notice, data);
  }

  @Override protected void convert(BaseViewHolder helper, GroupNotice item) {
    String allContent = item.getContent();
    if (allContent.contains(Constants.NOTICE_SEPARATE)) {
      String title = allContent.substring(0, allContent.indexOf(Constants.NOTICE_SEPARATE));
      String content = allContent.substring(
          allContent.indexOf(Constants.NOTICE_SEPARATE) + Constants.NOTICE_SEPARATE.length(),
          allContent.length());
      helper.setText(R.id.tv_title, title);
      helper.setText(R.id.tv_content, content);
    } else {
      helper.setText(R.id.tv_title, allContent);
      helper.setText(R.id.tv_content, allContent);
    }
    helper.setText(R.id.tv_user_name, item.getUSER_NAME());
    helper.setText(R.id.tv_time, item.getTime().substring(0, 10));
  }
}
